Allow inversion of boolean cmdline parameters with 'no-' prefix.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 9 Jul 2007 13:13:56 +0000 (14:13 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 9 Jul 2007 13:13:56 +0000 (14:13 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/common/kernel.c
xen/include/xen/init.h

index f8e4f11a0ebecd0bf5e48677990f74450bf6c8f4..fea3224a767a37b32d13b854ea500d3160e7a216 100644 (file)
@@ -26,10 +26,11 @@ int tainted;
 
 void cmdline_parse(char *cmdline)
 {
-    char opt[100], *optval, *q;
+    char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
     struct kernel_param *param;
-    
+    int invbool;
+
     if ( p == NULL )
         return;
 
@@ -48,7 +49,7 @@ void cmdline_parse(char *cmdline)
             break;
 
         /* Grab the next whitespace-delimited option. */
-        q = opt;
+        q = optkey = opt;
         while ( (*p != ' ') && (*p != '\0') )
         {
             if ( (q-opt) < (sizeof(opt)-1) ) /* avoid overflow */
@@ -64,9 +65,14 @@ void cmdline_parse(char *cmdline)
         else
             optval = q;       /* default option value is empty string */
 
+        /* Boolean parameters can be inverted with 'no-' prefix. */
+        invbool = !strncmp("no-", optkey, 3);
+        if ( invbool )
+            optkey += 3;
+
         for ( param = &__setup_start; param <= &__setup_end; param++ )
         {
-            if ( strcmp(param->name, opt ) != 0 )
+            if ( strcmp(param->name, optkey) )
                 continue;
 
             switch ( param->type )
@@ -79,7 +85,10 @@ void cmdline_parse(char *cmdline)
                     simple_strtol(optval, (const char **)&optval, 0);
                 break;
             case OPT_BOOL:
-                *(int *)param->var = 1;
+                *(int *)param->var = !invbool;
+                break;
+            case OPT_INVBOOL:
+                *(int *)param->var = invbool;
                 break;
             case OPT_CUSTOM:
                 ((void (*)(const char *))param->var)(optval);
index 3ff3ff0e3788554751d1b46efada3625c9891b21..f5afd0cfa104bd00c3722086b411087010de671d 100644 (file)
@@ -78,7 +78,7 @@ extern initcall_t __initcall_start, __initcall_end;
  */
 struct kernel_param {
     const char *name;
-    enum { OPT_STR, OPT_UINT, OPT_BOOL, OPT_CUSTOM } type;
+    enum { OPT_STR, OPT_UINT, OPT_BOOL, OPT_INVBOOL, OPT_CUSTOM } type;
     void *var;
     unsigned int len;
 };
@@ -93,6 +93,10 @@ extern struct kernel_param __setup_start, __setup_end;
     static char __setup_str_##_var[] __initdata = _name; \
     static struct kernel_param __setup_##_var __attribute_used__ \
         __initsetup = { __setup_str_##_var, OPT_BOOL, &_var, sizeof(_var) }
+#define invboolean_param(_name, _var) \
+    static char __setup_str_##_var[] __initdata = _name; \
+    static struct kernel_param __setup_##_var __attribute_used__ \
+        __initsetup = { __setup_str_##_var, OPT_INVBOOL, &_var, sizeof(_var) }
 #define integer_param(_name, _var) \
     static char __setup_str_##_var[] __initdata = _name; \
     static struct kernel_param __setup_##_var __attribute_used__ \